/* -------------------
 * JSTLConstants.java
 * -------------------
 * Original Author:  Marcelo Augusto Garcia Gomes;
 * Contributor(s):   
 *
 * Changes (from 30/11/2009)
 *    
 * $Id$
 */
package br.com.ft.ecommerce.constante;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

public class JSTLConstants  extends HashMap<Object,Object> {

    private static final long serialVersionUID = -4107364945352245777L;
    private boolean initialised = false;
 
    
    public JSTLConstants() {
        Class<?> c = this.getClass();
        Field[] fields = c.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
 
            Field field = fields[i];
            int modifier = field.getModifiers();
            if (Modifier.isFinal(modifier) && !Modifier.isPrivate(modifier))
                try {
                    this.put(field.getName(), field.get(this));
                }
                catch (IllegalAccessException e) {}
        }
        initialised = true;
    }
 
    public void clear() {
        if (!initialised)
            super.clear();
        else
            throw new UnsupportedOperationException("Cannot modify this map");
    }
 
    public Object put(Object key, Object value) {
        if (!initialised)
            return super.put(key, value);
        else
            throw new UnsupportedOperationException("Cannot modify this map");
    }
 
    @SuppressWarnings("unchecked")
    public void putAll(Map m) {
        if (!initialised)
            super.putAll(m);
        else
            throw new UnsupportedOperationException("Cannot modify this map");
    }
 
    public Object remove(Object key) {
        if (!initialised)
            return super.remove(key);
        else
            throw new UnsupportedOperationException("Cannot modify this map");
    }
}
